using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ECommerce.Library.Web;
using eShop.Business;
using ECommerce.Library;
using System.Collections.Generic;
using eShop.Model;
using eShop.DataAccess;
using eShop.Business;


public partial class master_public : BaseMaster
{
    public static string rootPath = string.Empty;


    private String _BrandImageUrl
    {
        get
        {
            if (HttpContext.Current.Session["_BrandImageUrl"] != null)
            {
                return HttpContext.Current.Session["_BrandImageUrl"].ToString();
            }
            else
            {
                Manufacturer brand = ManufacturerManager.GetByBrandUrl(SupplierId);
                if (brand != null)
                {
                    HttpContext.Current.Session["_BrandImageUrl"] = brand.BrandBannerImageUrl;
                    return brand.BrandImageUrl;
                }
                else
                {
                    return String.Empty;
                }
            }
        }
        set 
        {
            HttpContext.Current.Session["_BrandImageUrl"] = value; 
        }
    }

    private String PartnerName
    {
        get
        {
            if (HttpContext.Current.Session["_PartnerName"] != null)
            {
                return HttpContext.Current.Session["_PartnerName"].ToString();
            }
            else
            {
                Manufacturer brand = ManufacturerManager.GetByBrandUrl(SupplierId);
                if (brand != null)
                {
                    HttpContext.Current.Session["_PartnerName"] = brand.BrandName;
                    _BrandImageUrl= brand.BrandImageUrl;
                    return brand.BrandName;
                }
                else
                {
                    return String.Empty;
                }
            }
        }
        set
        {
            HttpContext.Current.Session["_PartnerName"] = value;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadSiteUser();
        }
    }

    
   
    protected void LoadSiteUser()
    {
        try
        {
            hlkLogin.NavigateUrl = CustomSiteMap.Login;
            hlkMyAccount.NavigateUrl = CustomSiteMap.UserHome;
            if (SessionManager.IsUserLoggedIn)
            {
                User siteUser = SessionManager.LoggedUser;
                lkbLogout.Visible = true;
                hlkMyAccount.Visible = true;
                hlkLogin.Visible = false;
                litCustomerName.Text = "Welcome " + siteUser.Profile.FullName + " | ";
            }
            else
            {
                lkbLogout.Visible = false;
                hlkMyAccount.Visible = false;
                hlkLogin.Visible = true;
            }
        }
        catch
        {
            lkbLogout.Visible = false;
            hlkMyAccount.Visible = false;
            hlkLogin.Visible = true;
        }
    }
    protected void lkbLogout_Click(object sender, EventArgs e)
    {
        SessionManager.LoggedUser = null;
        CookieManager.SetCookieValue(CookieManager.USER_NAME, CookieManager.USER_NAME, DateTime.Now.AddDays(-1));
        CookieManager.SetCookieValue(CookieManager.PASSWORD, CookieManager.PASSWORD, DateTime.Now.AddDays(-1));
        Response.Redirect(CustomSiteMap.Home);
    }

    protected void Search_Click(object sender, EventArgs e)
    {
        SessionManager.SearchKeyword = tbxSearchKeyword.Text.Trim().ToLower().Replace("keyword","");
        Response.Redirect(eShop.Business.CustomSiteMap.ProductsSearched);         
    }


}
